using Senparc.Weixin.Exceptions;
using System;
namespace Senparc.Weixin.MP.AppStore.Api
{
	public class ApiConnection
	{
		private Passport _passport;
		public ApiConnection(Passport passport)
		{
			if (passport == null)
			{
				throw new WeixinException("Passport不可以为NULL！");
			}
			this._passport = passport;
		}
		public IAppResult<T> Connection<T>(Func<IAppResult<T>> apiFunc) where T : IAppResultData
		{
			IAppResult<T> appResult = apiFunc();
			if (appResult.Result == AppResultKind.账户验证失败)
			{
				AppStoreManager.ApplyPassport(this._passport.AppKey, this._passport.Secret, this._passport.ApiUrl);
				appResult = apiFunc();
			}
			return appResult;
		}
	}
}
